package com.smartcampusbackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartcampusbackend.mapper.RepairTypeConfigMapper;
import com.smartcampusbackend.model.RepairTypeConfig;
import com.smartcampusbackend.service.RepairTypeConfigService;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class RepairTypeConfigServiceImpl extends ServiceImpl<RepairTypeConfigMapper, RepairTypeConfig> implements RepairTypeConfigService {

    @Override
    public List<RepairTypeConfig> getActiveTypes() {
        QueryWrapper<RepairTypeConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_active", true)
                   .orderByAsc("priority");
        return list(queryWrapper);
    }

    @Override
    public List<RepairTypeConfig> getAllTypes() {
        QueryWrapper<RepairTypeConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("priority");
        return list(queryWrapper);
    }

    @Override
    public RepairTypeConfig getTypeById(Integer id) {
        return getById(id);
    }

    @Override
    public boolean addType(RepairTypeConfig typeConfig) {
        return save(typeConfig);
    }

    @Override
    public boolean updateType(RepairTypeConfig typeConfig) {
        return updateById(typeConfig);
    }

    @Override
    public boolean deleteType(Integer id) {
        return removeById(id);
    }

    @Override
    public boolean toggleTypeStatus(Integer id, Boolean isActive) {
        RepairTypeConfig typeConfig = getById(id);
        if (typeConfig == null) {
            return false;
        }
        typeConfig.setIsActive(isActive);
        return updateById(typeConfig);
    }
} 